This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Error - Object reference not set to an instance of an object

Santhosh - Monday, February 21, 2011 6:50 AM:

Hi Community,

I'm trying to execute below method in an action for a project.

But I'm receiving an error message saying "Object reference not set to an instance of an object".

Could anyone help me where I'm going wrong in below given code.

Sub MethodMainsubroutine()
 Dim myInn As Innovator = New Innovator(Me.InnovatorObject)
 Dim curItem As Item = myInn.newItem()
 Dim strOutput As New StringBuilder()
 
 curItem.loadAML(inDom.selectSingleNode("//Item").outerXml)
 strOutput.Append("My ID: " & curItem.getId().ToString)
 Dim toplevelwbsItem As Item= myInn.newItem("WBS Element", "get") 'I guess this is the place where error is.
 toplevelwbsItem.setProperty("id", curItem.getProperty("wbs_id").ToString)
 toplevelwbsItem.setAttribute("select", "*")
 toplevelwbsItem.apply()
 If (toplevelwbsItem.isError()) Then
    outDom.LoadXml(myInn.newError("Error retrieving related items").dom.outerXML)
 End If
 strOutput.Append("Top Level WBS Item: " & toplevelwbsItem.getProperty("keyed_name").ToString)

 outDom.LoadXml(myInn.newResult(strOutput.ToString).dom.outerXML)
End Sub

In the above code "curItem" is Project Item type.

Please help

Santhosh



jenC - Monday, February 21, 2011 2:31 PM:

You usually get that error if you are trying to access the properties of a null object.

The piece of your code that looks most suspect is:
inDom.selectSingleNode("//Item").outerXml  <--- if there is no //Item selectSingleNode won't find anything so it would give you that error.

if curItem doesn't get populated on that line, all of the others are likely to fail as well.

You can add debug lines like CCO.Utilities.WriteDebug("MyDebugFile", "I'm on line 2") all over your code to pin down exactly where the error is happening. (Find the log file in .InnovatorServer emp)

 



Santhosh - Tuesday, February 22, 2011 1:38 AM:

Hi JenC,

I think  curItem.loadAML(inDom.selectSingleNode("//Item").outerXml) is returning an item.

Because just below that line of code, I'm accessing the curItem ID and appending to a string builder. 
 strOutput.Append("My ID: " & curItem.getId().ToString)

I have tested this and I'm able to see the ID as output.

Error is coming only when I try to create item of another type.

Santhosh



Brian - Tuesday, February 22, 2011 4:17 AM:

Hi Santhosh,

Have you debugged step by step through the code?

You suggest that the code is failing on one line and then say that the next line is working. The program would not get to the next line if the one you have highlighted is actually failing.

I'm going to guess that you are really trying to do this:

 

Dim myInn As Innovator = Me.getInnovator()

 

Dim tlwbsItem As Item = myInn.newItem("WBS Element", "get")

tlwbsItem.setID(Me.getProperty("wbs_id"))

tlwbsItem = tlwbsItem.apply()

If ( tlwbsItem.isError() ) Then

    Return myInn.newError(tlwbsItem.getErrorString())

End If

Return tlwbsItem

That is: You are trying to get the Top Level WBS Item out of the project Item.

The Innovator Item methods are designed to help you manipulate the AML that is coming out of the server. You don't need to get into XML handling all that often.

Also if this is running from an Action of type "Item" then the "Me" context is the "Project" item that is selected by the user.

Hope this helps.

Brian.



Santhosh - Wednesday, March 2, 2011 6:45 AM:

I got the solution for this.

thanks everyone.